package com.fwj.designpattern.singleton;

/**
 * Project Name: fwj
 * Author: fhw
 * File Name: HungrySingleton  饿汉模式
 * desc 加载类就初始化
 * Package Name: com.fwj.designpattern.singleton
 * Date: 2020/7/4 11:18 下午
 * Copyright (c) 2020,All Rights Reserved.
 */
public class HungrySingleton {


    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(instance);
            }
        }).start();
        // ---------------------------------------------------------
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(instance);
            }
        }).start();
    }


    private static HungrySingleton instance = new HungrySingleton();

    public static HungrySingleton getInstance() {
        return instance;
    }

    private HungrySingleton() {
    }

}